// Filename:    main.cpp
// Author:      John Van Drasek
// Date:		4/2/2011
// Description: This is a test version to show all pieces working in a sinle app.
//				We are using RequestListener, ResponseListener, and JobLoop

// Includes
// Windows
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// Application
#include "AJ_Globals.h"
#include "AJ_RequestListener.h"
#include "AJ_ResponseListener.h"
#include "AJ_RequestSender.h"

#define COMMANDSIZE 20

void AutoJobHelp()
{
	printf("\n");
	printf("*****************************************************************\n");
	printf("*** help: ****\n");
	printf("**************\n");
	printf("aj_help           - Display list of commands\n");
	printf("exit              - Shutdown all threads and exit\n");
	printf("*****************************************************************\n\n");
}

int AutoJobExec(char* str)
{
	int result = AJ_FAIL;

	if(strcmp(str,"aj_help") == 0)
	{
		AutoJobHelp();
	}
	else if(strcmp(str,"exit") == 0)
	{
		result = RequestListener_Destroy();
		result = ResponseListener_Destroy();
	}
	else if(strcmp(str,"send") == 0)
	{
		// This is where we send data to be executed on the remote system
		RequestSender("127.0.0.1", "dir&&dir");
	}
	else
	{
		//DisplayPrompt();
		RequestSender("127.0.0.1", str);
	}

	return result;
}

int main(int argc, char* argv[])
{
	int result = AJ_FAIL;
	char str[COMMANDSIZE];
	memset(str,0,COMMANDSIZE);

	// Start RequestListener
	result = RequestListener_Init();

	// Start ResponseListener
	result = ResponseListener_Init();

	printf("\n***********\n");
	printf("* AutoJob *\n");
	printf("***********\n\n");
	printf("type: aj_help for Help menu.\n\n\n\n");

	// Start JobLoop
	while((strcmp(((char*)(&str)),"exit") != 0))
	{
		memset(str,0,COMMANDSIZE);
		scanf("%s",str);  // FIXME: this needs to be changed, but scanf_s causes problems :/ need to look into it
		result = AutoJobExec(((char*)(&str)));
	}

	return AJ_SUCCESS;
}